import os
from pathlib import Path

DATA_DIR = Path(__file__).parent.parent.joinpath("data")
#SOURCE_DIR = DATA_DIR.joinpath("stock_data/source")
#SOURCE_DIR.mkdir(exist_ok=True, parents=True)
CN_CSVS = DATA_DIR.joinpath('cn_csv')
CN_CSVS.mkdir(exist_ok=True, parents=True)

PIT_CSVS = DATA_DIR.joinpath('fin_csv')
PIT_CSVS.mkdir(exist_ok=True, parents=True)

CN_CSVS_UPDATE = DATA_DIR.joinpath('cn_csv_update')
CN_CSVS_UPDATE.mkdir(exist_ok=True, parents=True)

QLIB_DIR = DATA_DIR.joinpath("qlib_data")
QLIB_DIR.mkdir(exist_ok=True, parents=True)
CN_DATA_TEST = QLIB_DIR.joinpath('cn_data_test')
CN_DATA_TEST.mkdir(exist_ok=True, parents=True)

CN_DATA = QLIB_DIR.joinpath('cn_data')


def get_index_codes():
    return [
        '000300.SH',
        '000905.SH',
        '399006.SZ',  # 创业板
        '000852.SH',  # 中证1000
        '399324.SZ',  # 深证红利
        '000922.SH',  # 中证红利
        '399997.SZ',  # 中证白酒
        '399396.SZ',  # 食品饮料

        '000013.SH',  # 上证企债
        '000016.SH'  # 上证50
    ]


def get_global_index_codes():
    return {
        'HSI': '恒生指数',
        'SPX': '标准普尔500指数',
        'IXIC': '纳斯达克指数',
        'GDAXI': '德国DAX指数',
        'N225': '日经225指数',
    }


class GlobalEvent:
    MSG_TYPE_SERIES = 1
    TASK_CHANGED = 2
    GRAPH_RESULT = 3
    MESSAGE = 5

    BKT_START = 10
    BKT_FINISHED = 11
    BKT_PROGRESS = 12

    def __init__(self):
        self.observers = []

    def add_observer(self, observer):
        self.observers.append(observer)

    def notify(self, event_type, data):
        for o in self.observers:
            data.update({'event_type': event_type})


G = GlobalEvent()

